﻿using System.Text.RegularExpressions;

namespace TianYu.Core.Common
{
    public class RegexUtils
    {
        /// <summary>是否IP地址字符串</summary>   
        public static bool IsIPAddress(string input) => Regex.IsMatch(input, RegexPattern.IPAddress);

        /// <summary>校验手机号码</summary>
        public static bool IsPhone(string input) => Regex.IsMatch(input, RegexPattern.Phone); 

        /// <summary>是否包含中文名</summary>
        public static bool ContainCN(string input) => Regex.IsMatch(input, RegexPattern.ContainCN);

        /// <summary>是否是字母</summary>
        public static bool IsLetter(string input) => Regex.IsMatch(input, RegexPattern.Letter);

        /// <summary>是否域名</summary>
        public static bool IsDomain(string input) => Regex.IsMatch(input, RegexPattern.Domain);
    }

    public static class RegexPattern
    {  
        public const string Phone = "^[1]([3-9])[0-9]{9}$";

        public const string IPAddress = @"^((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})(\.((2(5[0-5]|[0-4]\d))|[0-1]?\d{1,2})){3}$"; 

        public const string ContainCN = @"^[\u4e00-\u9fa5]";

        public const string Letter = @"^[A-Za-z]"; 

        public const string Domain = @"^[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$"; 
    }
}
